import {BrowserWindow, Point, screen} from 'electron'
import {MOUSE_MOVE_EVENT} from '@/utils/event'

let lastPoint: Point

export default function watchMouseMove(win: BrowserWindow) {
  // 100ms监听一次鼠标移动
  setInterval(() => {
    let point = screen.getCursorScreenPoint()
    if (lastPoint && (lastPoint.x !== point.x || lastPoint.y !== point.y)) {
      win.webContents.send(MOUSE_MOVE_EVENT, point)
    }

    lastPoint = point
  }, 100)
}